<?php

namespace App;

use Illuminate\Notifications\Notifiable;
use Illuminate\Contracts\Auth\MustVerifyEmail;
use Illuminate\Foundation\Auth\User as Authenticatable;
use Zizaco\Entrust\Traits\EntrustUserTrait;


/**
 * App\User
 *
 * @property int $id
 * @property string|null $username 用户名
 * @property string|null $admin_name 管理员名字
 * @property string|null $email 用户邮箱
 * @property string|null $phone 用户电话
 * @property string|null $wx_unionid unionid 针对微信登录用户
 * @property string|null $wx_openid openid 针对微信登录用户
 * @property string|null $wx_session_key 微信返回的状态
 * @property string $password 密码
 * @property string|null $user_key 用户标识
 * @property string $reg_ip 注册ip
 * @property string $reg_time 注册时间
 * @property string|null $login_ip 最后登录ip
 * @property string|null $login_time 最后登录时间
 * @property int|null $login_count 登录次数
 * @property int $role 登录角色 0：普通用户 1：管理员用户
 * @property int $status 用户状态,0锁定,1正常
 * @property string|null $remember_token
 * @property string|null $deleted_at
 * @property \Illuminate\Support\Carbon|null $created_at
 * @property \Illuminate\Support\Carbon|null $updated_at
 * @property-read \Illuminate\Notifications\DatabaseNotificationCollection|\Illuminate\Notifications\DatabaseNotification[] $notifications
 * @property-read int|null $notifications_count
 * @property-read \Illuminate\Database\Eloquent\Collection|\App\Role[] $roles
 * @property-read int|null $roles_count
 * @property-read \App\UserInfo $userInfo
 * @method static \Illuminate\Database\Eloquent\Builder|\App\User newModelQuery()
 * @method static \Illuminate\Database\Eloquent\Builder|\App\User newQuery()
 * @method static \Illuminate\Database\Eloquent\Builder|\App\User query()
 * @method static \Illuminate\Database\Eloquent\Builder|\App\User whereAdminName($value)
 * @method static \Illuminate\Database\Eloquent\Builder|\App\User whereCreatedAt($value)
 * @method static \Illuminate\Database\Eloquent\Builder|\App\User whereDeletedAt($value)
 * @method static \Illuminate\Database\Eloquent\Builder|\App\User whereEmail($value)
 * @method static \Illuminate\Database\Eloquent\Builder|\App\User whereId($value)
 * @method static \Illuminate\Database\Eloquent\Builder|\App\User whereLoginCount($value)
 * @method static \Illuminate\Database\Eloquent\Builder|\App\User whereLoginIp($value)
 * @method static \Illuminate\Database\Eloquent\Builder|\App\User whereLoginTime($value)
 * @method static \Illuminate\Database\Eloquent\Builder|\App\User wherePassword($value)
 * @method static \Illuminate\Database\Eloquent\Builder|\App\User wherePhone($value)
 * @method static \Illuminate\Database\Eloquent\Builder|\App\User whereRegIp($value)
 * @method static \Illuminate\Database\Eloquent\Builder|\App\User whereRegTime($value)
 * @method static \Illuminate\Database\Eloquent\Builder|\App\User whereRememberToken($value)
 * @method static \Illuminate\Database\Eloquent\Builder|\App\User whereRole($value)
 * @method static \Illuminate\Database\Eloquent\Builder|\App\User whereStatus($value)
 * @method static \Illuminate\Database\Eloquent\Builder|\App\User whereUpdatedAt($value)
 * @method static \Illuminate\Database\Eloquent\Builder|\App\User whereUserKey($value)
 * @method static \Illuminate\Database\Eloquent\Builder|\App\User whereUsername($value)
 * @method static \Illuminate\Database\Eloquent\Builder|\App\User whereWxOpenid($value)
 * @method static \Illuminate\Database\Eloquent\Builder|\App\User whereWxSessionKey($value)
 * @method static \Illuminate\Database\Eloquent\Builder|\App\User whereWxUnionid($value)
 * @method static \Illuminate\Database\Eloquent\Builder|\App\User withRole($role)
 * @mixin \Eloquent
 * @property int $enterprise_id 商家id
 * @method static \Illuminate\Database\Eloquent\Builder|\App\User whereEnterpriseId($value)
 * @property int $invite_user_id 邀请用户
 * @method static \Illuminate\Database\Eloquent\Builder|\App\User whereInviteUserId($value)
 */
class User extends Authenticatable
{
    use Notifiable;
    use EntrustUserTrait;


    /**
     * The attributes that are mass assignable.
     *
     * @var array
     */
    protected $table = 'users';
    protected $fillable = [
        'name', 'email', 'password',
    ];

    /**
     * The attributes that should be hidden for arrays.
     *
     * @var array
     */
    protected $hidden = [
        'password', 'remember_token',
    ];

    /**
     * The attributes that should be cast to native types.
     *
     * @var array
     */
    protected $casts = [
        'email_verified_at' => 'datetime',
    ];
    public function userInfo(){
        return $this->hasOne('App\UserInfo','user_id');
    }

    public static function getUserDetail($user_id){
        $user       = self::whereId($user_id)->first();
        $userInfo   = UserInfo::whereUserId($user_id)->first();
        return [
            'user'=>$user,
            'user_info'=>$userInfo
        ];
    }
}
